<?php

namespace app\common\model;

use app\common\service\ModelService;
use app\common\model\CompanyModel;


/**  TX
 *   账户表 模型
 *   Date: 2020/8/11
 * Class AccountRecordModel
 * @package app\api\model
 */
class AccountModel extends ModelService
{

    // 表名
    protected $name = 'account';


    public function getCompanyInfo($company_id = 1, $o_sn = '', $a_sn = '')
    {
        //查询企业信息
        $company_model = new CompanyModel();
        $field = 'app_sn,company_id,app_sn,account,company_no,company_name,business_license_pic,company_addr,email,telphone,contacts,contacts_tel,company_seal,seal_code,status,create_time,crm_web_url,achievement_web_url,remarks';
        $company_info = $company_model->getOne(['company_id' => $company_id], $field);

        $data = $company_info;
        if (!empty($company_info)) {
            $where['company_no'] = $company_info['company_no'];
            $where['account_role'] = 1;
            if (!empty($o_sn)) {
                $where['account_sn'] = $o_sn;
                $where['account_role'] = 2;//运营中心
            }
            if (!empty($a_sn)) {
                $where['account_sn'] = $a_sn;
                $where['account_role'] = 3;//城市合伙人
            }
            $account_info = self::getOne($where, 'id,app_sn,company_no,account_role,account_sn,total_money,current_money,threshold_money,threshold_switch');

            $data['account_id'] = $account_info['id'] ?? 0;
            $data['account_role'] = $account_info['account_role'] ?? '';
            $data['account_sn'] = $account_info['account_sn'] ?? '';
            $data['total_money'] = $account_info['total_money'] ?? 0;
            $data['current_money'] = $account_info['current_money'] ?? 0;
            $data['threshold_money'] = $account_info['threshold_money'] ?? 0;
            $data['threshold_switch'] = $account_info['threshold_switch'] ?? '';
        }
        return $data;
    }


}
